// CalcServer.h
// author: dipina@eside.deusto.es
#ifndef __NAMESERVER_H
#define __NAMESERVER_H

#include <fstream>
#include <iostream>
#include <map>
#include <sstream>

#include "TcpListener.h"
#include "Thread.h"
//** Modi 2.3.8
#include "SQLiteMap.h"

using namespace std;

namespace PracticaCaso
{
	class CalcServer: public TcpListener {
		private:
			string domain;
			map<string, string> dns2IpPortMap;
			SQLiteMap * sqliteMap;
			bool leerCache;

			
			void loadMappings(string mappinsFileName);
			string delegateExternalDnsServer(string serverDetails, string dnsName);
		public:
			CalcServer(int p, string m, bool leerCache);
			CalcServer(const CalcServer&);
			CalcServer & operator = (const CalcServer &);
			~CalcServer();
			string translate(string dnsEntry);
			friend ostream & operator << (ostream &os, CalcServer &n);

	};


	class CalcServerThread: public Thread {
		private:
			TcpClient* dnsClient;
			CalcServer& dnsServer;
			void run();
		public:
			CalcServerThread(TcpClient* c, CalcServer& s): dnsClient(c), dnsServer(s) {}
			~CalcServerThread();
	};
};
#endif
